<template>
  <div class="EditPassword">
      <group title="密码必须至少6个字符，而且同时包含字母和数字">
          <x-input v-model="old_password" :min="6" required label-width="80px" type="password" title="旧密码" placeholder="请填写旧密码"></x-input>
          <x-input v-model="password" :min="6" required label-width="80px" type="password" title="新密码" placeholder="请填写新密码"></x-input>
          <x-input v-model="repeat_password" :equal-with="password" :min="6" required label-width="80px" type="password" title="确认密码" placeholder="请再次输入新密码"></x-input>
      </group>
      <div style="padding:0 15px">
        <x-button @click.native="submit" style="margin-top:20px;" type="primary">确认修改</x-button>
      </div>
  </div>
</template>
<script>
import { XInput, Group, XButton } from "vux";
export default {
  name: "EditPassword",
  data() {
    return {
      old_password: "",
      password: "",
      repeat_password: ""
    };
  },
  computed: {
    correct() {
      return (
        this.password === this.repeat_password &&
        this.old_password.length >= 6 &&
        this.password.length >= 6 &&
        this.repeat_password.length >= 6
      );
    }
  },
  methods: {
    submit() {
      if (this.correct) {
        this.$http
          .post("/api/supplier.supplier_user/update", {
            type: "password",
            old_password: this.old_password,
            password: this.password,
            repeat_password: this.repeat_password
          })
          .then(res => {
            if (res.data.code) {
              this.$vux.toast.show({
                text: "修改成功"
              });
              this.$router.push({ name: "login" });
            }
          });
      }
    }
  },
  components: {
    XInput,
    Group,
    XButton
  }
};
</script>

<style scoped>

</style>

